﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;

namespace SnippetBox.Core.Data.Models {
    public class RoleName {
        public RoleName() { }
        public RoleName(string value, string name) {
            Value = value;
            Name = name;
        }

        public string Value { get; set; }
        public string Name { get; set; }

        public static List<RoleName> GetRoleNames() {
            var names = Enum.GetNames(typeof(Role));
            var values = Enum.GetValues(typeof(Role));

            var roleNames = new List<RoleName>();

            for (int i = 0; i < names.Length; i++) {
                var name = names[i];
                var value = values.GetValue(i).ToString();

                roleNames.Add(new RoleName(name, value));
            }

            return roleNames;
        }

        public static IEnumerable<SelectListItem> GetSelectList() {
            return GetRoleNames().Select(roleName => new SelectListItem 
            {
                Text = roleName.Name,
                Value = roleName.Value
            });
        }
    }
}